package com.ktjy.example.example01To02.factory;

import com.ktjy.example.example01To02.dao.PetDao;
import com.ktjy.example.example01To02.dao.impl.PetDaoMySqlImpl;
import com.ktjy.example.example01To02.dao.impl.PetDaoOracleImpl;

public class PetClassFactory {
    //读取properties配置文件进行修改
    public static String defaultBeanName = "petDaoMySqlImpl";

    /**
     * 根据名称获取对应的PetDao实现对象
     */
    public static PetDao getInstance(String beanName) {
        PetDao petDao = null;
        switch (beanName) {
            case "petDaoMySqlImpl":
                petDao = new PetDaoMySqlImpl();
                break;
            case "petDaoOracleImpl":
                petDao = new PetDaoOracleImpl();
                break;
            default:
                throw new RuntimeException("未找到" + beanName + "对应的对象");
        }
        return petDao;
    }
}
